#!/bin/sh
# System startup script for kliqj 3d-printer host code

### BEGIN INIT INFO
# Provides:          kliqj
# Required-Start:    $local_fs
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: kliqj daemon
# Description:       Starts the kliqj daemon.
### END INIT INFO
sudo chmod -R 777 /home/print3D/printer_data

case "$1" in
start)  echo  "#### 启动全家桶"
        LD_PRELOAD=/home/print3D/ioctlHook.so /etc/init.d/klipper start
        LD_PRELOAD=/home/print3D/ioctlHook.so /etc/init.d/moonraker start
        sudo /etc/init.d/nginxk  start
        grep "false" /root/print3D/ksdelay.sh > /dev/null
        if [ $? -ne 0 ]; then
           LD_PRELOAD=/home/print3D/ioctlHook.so /etc/init.d/KlipperScreen start
        fi
        echo  "#### 全家桶启动完成"
        ;;
stop)   echo  "#### 停止全家桶"
        grep "false" /root/print3D/ksdelay.sh > /dev/null
        if [ $? -ne 0 ]; then
           sudo /etc/init.d/KlipperScreen stop
        fi
        sudo /etc/init.d/nginxk  stop
        sudo /etc/init.d/moonraker stop
        sudo /etc/init.d/klipper stop
        echo  "#### 已停止全家桶"
        ;;
restart) echo  "#### 重新启动全家桶" 
        $0 stop
        $0 start
        ;;
esac
exit 0